package org.dding.msc.service;

import java.security.PrivilegedAction;

public final class SetTCCLAction implements PrivilegedAction<ClassLoader> {

    static final SetTCCLAction CLEAR_TCCL_ACTION = new SetTCCLAction(null);
    private final ClassLoader classLoader;

    public SetTCCLAction(final ClassLoader classLoader) {
        this.classLoader = classLoader;
    }

    public ClassLoader run() {
        try {
            return Thread.currentThread().getContextClassLoader();
        } finally {
            Thread.currentThread().setContextClassLoader(classLoader);
        }
    }
}
